#!bin/bash/

version=2.1.0
install_dir=/opt
app_admin_name=apollo-adminservice
app_config_name=apollo-configservice
app_portal_name=apollo-portal
mysql_host=127.0.0.1:3306
mysql_username=apollo
mysql_password='Apollo@1024!'

[[ ! `rpm -qa | grep unzip` ]] && yum install -y unzip

mkdir -p /opt/{${app_admin_name},${app_config_name},${app_portal_name}}

unzip -o ${app_admin_name}*.zip -d ${install_dir}/${app_admin_name}
unzip -o ${app_config_name}*.zip -d ${install_dir}/${app_config_name}
unzip -o ${app_portal_name}*.zip -d ${install_dir}/${app_portal_name}

sed_script="${sed_script}s/^spring.datasource.username.*/spring.datasource.username = ${mysql_username}/g;"
sed_script="${sed_script}s/^spring.datasource.password.*/spring.datasource.password = ${mysql_password}/g;"
sed_script="${sed_script}s#^spring.datasource.url.*3306#spring.datasource.url = jdbc:mysql://${mysql_host}#g;"

find ${install_dir}/{${app_admin_name},${app_config_name},${app_portal_name}} -type f -iname "*.properties" | xargs sed -i "${sed_script}"
find ${install_dir}/{${app_admin_name},${app_config_name},${app_portal_name}} -type f -iname "*.properties" | xargs grep -E "^spring.datasource"